// 用户注册接口
const Router = require('koa-router')
const { User } = require('../../models/user')
const { success } = require('../../lib/helper') //module.exports时导出对象,这里加括号
const router = new Router({
    prefix: '/v1/user'  //指定所有注册在路由上的中间件前缀
})

const { RegisterValidator } = require('../../validators/validator')

router.post('/register', async (ctx, next) => {
    const v = await new RegisterValidator().validate(ctx)
    const user = {
        email: v.get('body.email'),
        password: v.get('body.password2'),
        nickname: v.get('body.nickname')
    }
    await User.create(user)
    success() //使用
})

module.exports = router